#ifndef CFOLDERUPLOADLIB_H
#define CFOLDERUPLOADLIB_H

#include <functional>
#include <string>

#define CFOLDERUPLOADLIB_EXPORT __declspec(dllexport)

struct FolderUploadParam
{
    std::string local_root_path;    //utf-8 local root folder."D:/root/"
    std::string file_service_url;   //"http://127.0.0.1:4000/api/file"
    std::string file_suffix_upload; //要上传的文件后缀，如写入状态.wrting.写完成状态是.dat。该参数则配置为"dat",则只上传后缀为.dat的文件。
    bool delete_after_upload;       //上传完删除还是重命名
    uint16_t thread_count;          //上传线程数量。内部包含1个扫描线程和thread_count个上传线程。该参数最小为1。

    FolderUploadParam() {
        delete_after_upload = false;
        thread_count = 2;
    }
};

struct UpStatInfo
{
    uint64_t fail_count;
    uint64_t total_count;

    UpStatInfo() { reset(); }

    void reset()
    {
        fail_count = 0;
        total_count = 0;
    }
};

using ProgressCallback = std::function<void(UpStatInfo statInfo)>;// 进度回调函数类型

using CompleteCallback = std::function<void(bool success, const std::string& message)>;// 工作状态回调(若异常结束)

class CFolderUploadLib
{
public:

    virtual int setUploadParams(const FolderUploadParam&param) = 0;//设置上传参数
    virtual int startUpload() = 0;      // 开始上传
    virtual int stopUpload() = 0;       // 停止上传   
    virtual bool isUploading() const = 0;// 是否正在上传

    // 设置回调函数
    virtual void setProgressCallback(ProgressCallback callback) = 0;    
    virtual void setCompleteCallback(CompleteCallback callback) = 0;
};

CFOLDERUPLOADLIB_EXPORT CFolderUploadLib *CreateLibObject(int id);
CFOLDERUPLOADLIB_EXPORT void DestorytLibObject(CFolderUploadLib *obj);

#endif // CFOLDERUPLOADLIB_H
